﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using WSPDocumentBuilder_WPF.Managers;

namespace WSPDocumentBuilder_WPF.BLL
{
    public class DocInfoDocumentPathUrlResolver : XmlUrlResolver
    {
        private string _documentFolder = string.Empty;

        public DocInfoDocumentPathUrlResolver(string documentsFolder)
            : base()
        {
            _documentFolder = documentsFolder;
        }

        public override Uri ResolveUri(Uri baseUri, string relativeUri)
        {
            string resultString = relativeUri;
            if (baseUri == null)
            {
                string docFile = Path.GetFileName(relativeUri);
                resultString = _documentFolder + @"\" + docFile;
            }
            else
            {
                resultString = _documentFolder + @"\" + relativeUri;
            }

            return new Uri(resultString, UriKind.RelativeOrAbsolute);
        }
    }
}
